<?php
include_once '../init.inc.php';
if ($log->admincheck($_SESSION['loggedin'], "logon", "password", "useremail", $_SESSION['loggedusr']) == false){
    die(include("retry.php"));
    };
include_once 'header.php';
?>

    <h1> Добавить пользователя </h1>

    
    <?php
      $sql =  "SELECT * FROM `logon`";
       
        $result = mysql_query($sql) or die('Error, insert query failed');
    
    ?>
    
    
    
    
    
   <form action ="" method="get"> 
    
             <table class="vote_table">
                 <thead>
                 <th>id</th>
                 <th>mail</th>
                 <th>pass</th>
                 <th>user level</th>
                 </thead>

<?php
        
                    // вывод голосовавших
                        while ($row = mysql_fetch_assoc($result)) { ?>
                                    <tr>
         
                                        
                    <?php    foreach ($row as $key=>$cellValue){ 
                                        if ($key=="pollID") continue;
                                        if ($key=="pollQuestion")  {?>
                                        <td class="left-align">
                                           
                                              <?php echo excerpt($cellValue); ?>
                                          
                                        </td>
                                         <?php }else { ?>
                                             <td>
                                           
                                              <?php 
                                              
                                              echo excerpt($cellValue); ?>
                                          
                                             </td>
                                     
                                             
                                       <?php       
                                         }
                                                             
                                                                } 
                                        
                                       
                                ?></tr> 

        
                                    
                                    <?php
                   } 
       

 
 
 ?>
   
    
    
    
    
    
    
    
    
    

                                    <tr><td></td>                                   
  <td>user email:<br /><input name="user" value="<?=@$_REQUEST['user']?>" class ="searchInput" /> </td>
  <td>password:<br /><input name="password" value="<?=@$_REQUEST['password']?>" class ="searchInput" />  </td>
  <td>user level(1=admin):<br /><input name="level" value="<?=@$_REQUEST['level']?>" class ="searchInput" />   </td>
 </tr>
  <br />
   </table>            
    <br>
    
 <input type="submit" class ="searchButton" value="Добавить" />  
 
 
</form>
   

<?php

if(@$_REQUEST['user']&&@$_REQUEST['password']){


   $res = $log->register("", $_REQUEST['user'], $_REQUEST['password'], (int)$_REQUEST['level']);
   if (!$res){
       echo $log->error;
   }else {
       echo "<h2>Пользователь добавлен</h2>";
       echo "<script>location.href=\"admin_user.php\";</script>";
   }

}
?>

<?php include_once 'footer.php'; ?>